﻿
Imports elpmis
Imports webctrl

Namespace httpFunctions

    'parameters, page, optional, the xhtmlpage instance
    '            inlineScript, optional, the inlineScript of an xhtmlpage, overwrite page
    '            obj, the dest object
    '            value, any, convert to string by changeInnerHtmlById
    'return, string, action link
    Public MustInherit Class jsoperate
        Inherits internalFunction

        Class parameters
            Public Const page As String = "page"
            Public Const inlineScript As String = "inlineScript"
            Public Const i As String = "i"
            Public Const value As String = "value"
        End Class

        Protected Sub New(ByVal name As String)
            MyBase.New(name)
        End Sub

        Protected MustOverride Overloads Function invokeImpl(ByVal inlineScript As inlineScript, _
                                                             ByVal obj As String, ByVal value As Object) As String

        Protected NotOverridable Overrides Function invoke(ByVal ctx As context, _
                                                           ByRef output As bare_variable) As Boolean
            Dim i As String = Nothing
            If ctx.findVariableStr(parameters.i, i) Then
                Dim value As Object = Nothing
                If ctx.findVariable(Of Object)(parameters.value, value) Then
                    Dim inlineScript As inlineScript = Nothing
                    getinlinescript(ctx, inlineScript, parameters.page, parameters.inlineScript)
                    output = New bare_variable(typeDefination.string, _
                                               invokeImpl(inlineScript, i, value))
                    Return True
                Else
                    raiseError("expect parameter " + parameters.value, errorHandle.errorType.user)
                    Return False
                End If
            Else
                raiseError("expect parameter " + parameters.i, errorHandle.errorType.user)
                Return False
            End If
        End Function
    End Class

    'parameters, same as jsoperate
    'return, same as jsoperate
    Public Class jschangeValue
        Inherits jsoperate

        Public Sub New()
            MyBase.New("js.operate.value")
        End Sub

        Protected Overrides Function invokeImpl(ByVal inlineScript As inlineScript, _
                                                ByVal obj As String, ByVal value As Object) As String
            Return changeValue.invoke(inlineScript, obj, value)
        End Function
    End Class
End Namespace
